package com.jvtd.nettyim.im.server.handler;

import com.jvtd.nettyim.im.util.SessionUtil;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author Created by neal.zhang
 * @date 2020/5/30 - 15:55
 */
public class AuthHandler extends ChannelInboundHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        //如果未登录，关闭channel
        if (!SessionUtil.hasLogin(ctx.channel())) {
            ctx.channel().close();
        }else {
            //登录状态，移除校验
            ctx.pipeline().remove(this);
            super.channelRead(ctx, msg);
        }
    }
}
